package com.gxl.base.fx;

import com.gxl.base.fx.impl.MyType;

import java.util.ArrayList;
import java.util.List;

/**
 * @remark --
 * @author: GuoXiaolin
 * @date 2019/4/19 15:52
 * @Version 1.0
 * @Derction
 */
public class FxObject<T extends MyType> {

    private List<T> list = new ArrayList<>();

    public void say() {
        System.out.println("查询所有: ");
        for (T t : list) {
            System.out.println(t.say() + " 类型 : " + t.getClass());
        }
    }

    public void insert(T t) {
        System.out.println(t.say() + " --> 保存 "+ t.getClass());
        list.add(t);
    }

    public void delete(T t) {
        System.out.println(t.say() + " --> 删除 "+ t.getClass());
        list.remove(t);
    }

    public void update(T t) {
        System.out.println(t.say() + " --> 更新 "+ t.getClass());
        list.remove(t);
        list.add(t);
    }

    public T query(T t) {
        System.out.println(t.say() + " --> 查询 "+ t.getClass());
        return t;
    }

    public static void main(String[] args){

        FxObject fxObject = new FxObject();
        TypeA a = new TypeA("a5");
        TypeB b  = new TypeB("b5");

        fxObject.insert(a);
        fxObject.insert(b);
        fxObject.query(b);
        b  = new TypeB("1");
        fxObject.update(b);
        fxObject.delete(b);

        fxObject.say();

    }
}
